package ev.operator;//need to add this line

import ev.data.*;//need to add this line
import java.util.*;

public class Insertion implements Mutation {

	public Individual mutate(Individual old){

		int end=1;
		int start=0;

		int[] list=old.getList();
		int size=list.length;

		//generate two distinct positions randomly
		Random r=new Random();
		boolean rmdflag=true;

		while(rmdflag)
		{
			int A=r.nextInt(size);
			int B=r.nextInt(size);
			//System.out.println("A,B="+A+B);
			if(A>B)
			{
				start=B;
				end=A;
				rmdflag=false;
			}else if(A<B)
			{
				start=A;
				end=B;
				rmdflag=false;
			}
		}

		int tmp=list[end];

		start++;
		for(int i=end; i>start; i--)
		{
			list[i]=list[i-1];
		}

		list[start]=tmp;

		old.setList(list);
		return old;
	}
}
